| Conditions | 6 |
| Paths | 5 |
| Total Lines | 38 |
| Lines | 38 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | View Code Duplication | import { |
|
| 6 | var route = function(req, res, next){ |
||
| 7 | abeExtend.hooks.instance.trigger('beforeRoute', req, res, next) |
||
| 8 | if(typeof res._header !== 'undefined' && res._header !== null) return |
||
| 9 | |||
| 10 | let regUrl = /\/abe\/save\/(.*?)\/edit\// |
||
| 11 | var workflow = 'draft' |
||
| 12 | var match = req.originalUrl.match(regUrl) |
||
| 13 | if (match != null && match[1] != null) { |
||
| 14 | workflow = match[1] |
||
| 15 | } |
||
| 16 | var postUrl = req.originalUrl.replace(regUrl, '') |
||
| 17 | var json = req.body.json |
||
| 18 | |||
| 19 | var p |
||
| 20 | if (workflow === 'publish') { |
||
| 21 | p = cmsOperations.post.publish( |
||
| 22 | postUrl, |
||
| 23 | json |
||
| 24 | ) |
||
| 25 | }else { |
||
| 26 | p = cmsOperations.post.draft( |
||
| 27 | postUrl, |
||
| 28 | json, |
||
| 29 | workflow |
||
| 30 | ) |
||
| 31 | } |
||
| 32 | |||
| 33 | p.then((result) => { |
||
| 34 | res.set('Content-Type', 'application/json') |
||
| 35 | res.send(JSON.stringify(result)) |
||
| 36 | }, |
||
| 37 | (result) => { |
||
| 38 | res.set('Content-Type', 'application/json') |
||
| 39 | res.send(JSON.stringify(result)) |
||
| 40 | }).catch(function(e) { |
||
| 41 | console.error('[ERROR] post-reject.js', e) |
||
| 42 | }) |
||
| 43 | } |
||
| 44 | |||
| 45 | export default route |